/*
 * Copyright (C) 2010 Daniel Nilsson
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package afzkl.development.mColorPicker;

import com.organizadorestudiantil.R;
import afzkl.development.mColorPicker.views.ColorPickerView;
import afzkl.development.mColorPicker.views.ColorPickerView.OnColorChangedListener;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.PixelFormat;
import android.view.LayoutInflater;
import android.view.View;

public class ColorPickerDialog extends AlertDialog implements
		ColorPickerView.OnColorChangedListener {

	private ColorPickerView mColorPicker;
	private OnColorChangedListener mListener;
	
	public ColorPickerDialog(Context context, int initialColor) {		
		super(context);
		init(initialColor);
	}
	
	private void init(int color) {
		getWindow().setFormat(PixelFormat.RGBA_8888);
		setUp(color);
	}

	private void setUp(int color) {
		LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View layout = inflater.inflate(R.layout.dialog_color_picker, null);
		setView(layout);
		setTitle("Elige un color");
		mColorPicker = (ColorPickerView) layout.findViewById(R.id.color_picker_view);		
		mColorPicker.setOnColorChangedListener(this);
		mColorPicker.setColor(color, true);	
	}
	
	@Override
	public void onColorChanged(int color) {
		if (mListener != null) {
			mListener.onColorChanged(color);
		}
	}	
}